import { Commit } from "vuex/types/index";
import {
  IProject,
  IProjectItem,
  IJobs,
  IJobItem,
  ITasks,
  ITaskItem,
} from "@/components/Project/index";

interface IContactPerson {
  userID: string;
  userName: string;
  tel: string;
  location: string;
}
export const ProjectsStore = {
  namespaced: true,
  state: {
    contactPersonList: [],
    selfAvatar: "https://cdn.vuetifyjs.com/images/lists/2.jpg",
    selectedProject: null,
    jobs: null,
    selectedJob: null,
    tasks: null,
    selectedTask: null,
    projects: null,
  },
  mutations: {
    setProjects(
      state: { projects: IProject[] | null },
      projects: IProject[] | null
    ) {
      state.projects = projects;
    },
    setSelectedProject(
      state: { selectedProject: IProjectItem | null },
      project: IProjectItem | null
    ) {
      state.selectedProject = project;
    },
    setJobs(state: { jobs: IJobs | null }, jobs: IJobs | null) {
      state.jobs = jobs;
    },
    setSelectedJob(
      state: { selectedJob: IJobItem | null },
      selectedJob: IJobItem | null
    ) {
      state.selectedJob = selectedJob;
    },
    setTasks(state: { tasks: ITasks | null }, tasks: ITasks | null) {
      state.tasks = tasks;
    },
    setSelectedTask(
      state: { selectedTask: ITaskItem | null },
      selectedTask: ITaskItem | null
    ) {
      state.selectedTask = selectedTask;
    },
    updateContactPersonList(
      state: { contactPersonList: Array<IContactPerson> },
      contactPersonList: Array<IContactPerson>
    ) {
      state.contactPersonList = contactPersonList;
    },
  },
  actions: {
    refreshContactPersonList(context: { commit: Commit }) {
      const contactPersonList = [
        {
          userID: "Tim",
          userName: "Tim Wong",
          tel: "6382 9840",
          location: "Office",
        },
        {
          userID: "Yanny",
          userName: "Yanny Chan",
          tel: "9348 2322",
          location: "Warehouse",
        },
      ];
      setTimeout(() => {
        context.commit("updateContactPersonList", contactPersonList);
      }, 10000);
    },
  },
};
